<html>
<head>
    <title>Title</title>
</head>
<meta charset="utf-8">
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/laypage.css">

<script src="/js/jquery/jquery.min.js"></script>
<script src="/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
<script src="/js/jquery.validation/1.14.0/messages_zh.min.js"></script>
<style>
    input.error {
        border: 1px solid #ac2925;
    }
</style>
<body>
<div class="container">
    <form id="updateAssistantForm">
        <br/>
        <div class="form-group">
            <label for="assistant_id">工号：</label>
            <input type="text" class="form-control" id="assistant_id" name="assistant_id"
                   value="${assistant.assistant_id}"
                   placeholder="输入工号">
        </div>
        <div class="form-group">
            <label for="school_name">辅导员：</label>
            <input type="text" class="form-control" id="school_name" name="school_name"
                   value="${assistant.assistant_name}" placeholder="输入辅导员姓名">
        </div>
        <div class="form-group">
            <label for="phone">手机号：</label>
            <input type="text" class="form-control" id="phone" name="phone" value="${assistant.phone}"
                   placeholder="输入手机号">
        </div>

        <div class="form-group">
            <label for="pwd">密码：</label>
            <input type="text" class="form-control" id="pwd" name="pwd" value="${assistant.pwd}" placeholder="输入密码">
        </div>
        <div class="form-group">
            <label for="dept_id">院系：</label>
            <input type="text" class="form-control" id="dept_id" name="dept_id" value="${assistant.dept}">
        </div>
        <div class="form-group">
            <label for="email">邮箱：</label>
            <input type="text" class="form-control" id="email" name="email" value="${assistant.email}"
                   placeholder="输入邮箱">
        </div>
        <div class="form-group">
            <label for="assistant_state">在线状态：</label>
            <input type="text" class="form-control" id="assistant_state" name="assistant_state"
                   value="${assistant.assistant_state}">
        </div>
        <div class="form-group">
            <label for="role_id">角色：</label>
            <input type="text" class="form-control" id="role_id" name="role_id" value="${assistant.role}">
        </div>

        <div class="form-group">
            <button type="button" id="saveBtn" class="btn btn-success">修改</button>
            <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
        </div>
    </form>
</div>
<script>
    var updateAssistant = function () {
        //如果不符合校验规则，就返回
        if (!check().form()) {
            return;
        }
        $.ajax({
            type: "GET",
            dataType: "json",
            url: "/assistant/toUpdateAssistant.do",
            data: {
                "assistant_id": $("#assistant_id").val(),
                "assistant_name": $("#assistant_name").val(),
                "phone": $("#phone").val(),
                "pwd": $("#pwd").val(),
                "dept_id": $("#dept_id").val(),
                "email": $("#email").val(),
                "assistant_state": $("#assistant_state").val(),
                "role_id": $("#role_id").val()
            },
            success: function () {
                $("#cancelBtn").click();
            }
        });
    }


    $("#saveBtn").click(function () {
        updateAssistant();
    });

    $("#cancelBtn").click(function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.getAssistantPageList();
        parent.layer.close(index);
    });


    function check() {
        return $("#updateAssistantForm").validate({
            rules: {
                assistant_id: {
                    required: true
                },
                assistant_name: {
                    required: true
                },
                phone: {
                    required: true
                },
                pwd: {
                    required: true
                },
                dept_id: {
                    required: true
                },
                email: {
                    required: true
                },
                assistant_state: {
                    required: true
                },
                role_id: {
                    required: true
                }
            },
            messages: {
                assistant_id: {
                    required: ""
                },
                assistant_name: {
                    required: ""
                },
                phone: {
                    required: ""
                },
                pwd: {
                    required: ""
                },
                dept_id: {
                    required: ""
                },
                email: {
                    required: ""
                },
                assistant_state: {
                    required: ""
                },
                role_id: {
                    required: ""
                }
            }
        });
    }
</script>

</body>
</html>
